<?php
class cls_serve_productlist extends cls_serve_base
{
	function get_product_list($product_category,$current_page)
	{
		$category_data=cls_data_base::get_instance($this->name);
		$category_level=$this->get_category_level($product_category);
		if ($category_level==2)
		{
			$category[0]= $product_category;
		}
		if ($category_level==1)
		{		
			$category=$category_data->get_category_child($product_category);
		}
		for($i=0;!empty($category[$i]);$i++)
		{
			$product_list=$category_data->get_product_list($category[$i]);
		}
		return $product_list;
	}
	
	function get_parent_type_list($product_category)
	{
		$category_data=cls_data_base::get_instance($this->name);
		$category_level=$this->get_category_level($product_category);
		if ($category_level==2)
		{
			$category[0]= $product_category;
		}
		if ($category_level==1)
		{
			$category=$category_data->get_category_child($product_category);
		}
		for($i=0;!empty($category[$i]);$i++)
		{
		$category_name=$category_data->get_category_name($category[$i]);
		$product_list["$category_name"]=$category_data->get_product_list_top4($category[$i]);
		}
		
		return $product_list;
	}
	
	function get_category_level($product_category)
	{
		$category_data=cls_data_base::get_instance($this->name);
		$category_level=$category_data->get_category_level($product_category);
		$re=$category_level['lvl'];
		return $re;
	}
/*	
	function get_category_child($product_category)
	{
		$category_data=cls_data_base::get_instance($this->name);
		$category_level=$this->get_category_level($product_category);
		if ($category_level==2)
		{
			return $product_category;
		}
		if ($category_level==1)
		{
			$product_category=$category_data->get_category_child($product_category);
			return $product_category;
		}			
	}*/
	
	function get_product($product_category)
	{
		$category_data=cls_data_base::get_instance($this->name);
		$category_level=$this->get_category_level($product_category);
		if ($category_level==2)
		{
			$product_category= $product_category;
		}
		if ($category_level==1)
		{
			$product_category=$category_data->get_category_child($product_category);
		}					
	}
	
	function get_current_price($product_id)
	{
		$product_data = cls_data_base::get_instance($this->name);
		$product_info=$product_data->get_product_info($product_id);
		$discount_info=$product_data->get_product_discount($product_id);
		if ($discount_info['DiscountType']==1&&$discount_info['Status']==1)
		{
			$current_price=$product_info['Price']*$discount_info['Amount'];
			return $current_price;
		}
		if ($discount_info['DiscountType']==2&&$discount_info['Status']==1)
		{
			$current_price=$product_info['Price']-$discount_info['Amount'];
			return $current_price;
		}
		else
			return $product_info['Price'];
	}
	
	function this_product_list($product_id)
	{
		$product_data = cls_data_base::get_instance($this->name);
		$product_info=$product_data->get_product_info($product_id);
		
	}
	
	function get_category_parent($product_category)
	{
		$category_data = cls_data_base::get_instance($this->name);
		$category_info=$category_data->get_category_parent($product_category);
		return $category_info[0];
	}
	
	function get_category_child($product_category)
	{
		$category_data = cls_data_base::get_instance($this->name);
		$category_info=$category_data->get_category_child($product_category);
		return $category_info;
	}
	
	function get_category_name($product_category)
	{
		$category_data = cls_data_base::get_instance($this->name);
		$category_info=$category_data->get_category_name($product_category);
		return $category_info;
	}
	
	function get_original_category()
	{
		$category_data = cls_data_base::get_instance($this->name);
		$original_category=$category_data->get_original_category();
		return $original_category;
	}
}